import sys

def evaluate():
    files = ['a','b','c','d','e','f','g','h','j','k','l','m','n','p','r']
    for f in files:
        data = open('data/tagged/b1-cat-{0}.tagged'.format(f), 'r')
        line = data.readline()
        while line:
            nouns = []
            verbs = []
            l = line.strip()
            pair = l.split('/')
            while not pair[1] == '.':
                if pair[1] == 'VB' or pair[1] == 'VBD' or pair[1] == 'VBG' or pair[1] == 'VBN' or pair[1] == 'VBP' or pair[1] == 'VBZ':
                    verbs += [pair[0]]
                elif pair[1] == 'NN' or pair[1] == 'NNS' or pair[1] == 'NNP' or pair[1] == 'NNPS':
                    nouns += [pair[0]]
                line = data.readline()
                l = line.strip()
                pair = l.split('/')
            for n in nouns:
                for v in verbs:
                    print '{0} {1}'.format(n,v)
            line = data.readline()
        data.close()

def evaluate2():
    data = open('/Users/benkornacki/Documents/Michael Collins/tagging/part_of_speech/wsj/tagged', 'r')
    distance = 5
    line = data.readline()
    while line:
        l = line.strip()
        vals = l.split()
        for i in range(len(vals)):
            pair = vals[i].split('_')
            if not (pair[1] == 'NN' or pair[1] == 'NNS' or pair[1] == 'NNP' or pair[1] == 'NNPS'):
                continue
            lower = i-distance
            upper = i
            if lower < 0:
                lower = 0
            if upper > len(vals)-1:
                upper = len(vals)-1
            for j in range(lower,upper+1):
                pair2 = vals[j].split('_')
                if pair2[1] == 'VB' or pair2[1] == 'VBD' or pair2[1] == 'VBG' or pair2[1] == 'VBN' or pair2[1] == 'VBP' or pair2[1] == 'VBZ':
                    print '{0} {1}'.format(pair[0],pair2[0])
        line = data.readline()
    data.close()
                

evaluate2()
